#!/bin/bash
clear

TEXT='\033[30;107;2m'
INFO='\033[97;44m'
WARNING='\033[97;43m'
ERROR='\033[97;41m'
SUCCESS='\033[97;42m'
GREEN='\033[92m'
YELLOW='\033[93m'
RESET='\033[0m'

if [ "${EUID}" -ne 0 ]; then
    echo -e "${ERROR} ERROR ${RESET}${TEXT} You need to run this script as root! ${RESET}"; exit 1
fi

read -p "Enter username" _namapengguna
egrep "^$_namapengguna" /etc/shadowsocks-libev/.accounts &>/dev/null
if [ $? -ne 0 ]; then
    echo -e "${SUCCESS} INFO ${RESET}${TEXT} Username not exist! ${RESET}"
fi
read -p "Active duration" _tempohaktif
old_tarikh_luput=$( grep -w "$_namapengguna" /etc/shadowsocks-libev/.accounts | cut -d ' ' -f 9 )
tanggal_hari_ini=$(date +"%F")
tanggal_hari_ini=$(date -d "$tanggal_hari_ini")

old_tempoh_aktif=$((old_tarikh_luput - tanggal_hari_ini))
new_tempoh_aktif=$((old_tempoh_aktif + _tempohaktif))
new_tarikh_luput=$(date -d "$new_tempoh_aktif days" +"%F")

clear
echo
echo -e "${TEXT} ========================================================== ${RESET}"
echo -e "${TEXT} SS-LIBEV - RENEW ACCOUNT                                   ${RESET}"
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo
echo -e "${YELLOW} Username:${PLAIN} ${GREEN}$_namapengguna${PLAIN}"
echo -e "${YELLOW} Duration:${PLAIN} ${GREEN}$_tempohaktif days${PLAIN}"
echo -e "${YELLOW}  Expired:${PLAIN} ${GREEN}$new_tarikh_luput${PLAIN}"
echo
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo -e "${TEXT} Created by Doctype, Powered by Cybertize.                  ${RESET}"
echo -e "${TEXT} Copyright 2021, Allright Reserved.                         ${RESET}"
echo -e "${TEXT} ========================================================== ${RESET}"
echo
